home *** CD-ROM | disk | FTP | other *** search
/ Aminet 38 / Aminet 38 (2000)(Schatztruhe)[!][Aug 2000].iso / Aminet / dev / asm / fastsincos.readme < prev    next >
Encoding:
Text File  |  2000-07-01  |  5.2 KB  |  153 lines

  1. Short:    Very fast trigonom. funcs for 040/060.
  2. Author:   astegema@ix.urz.uni-heidelberg.de (Achim Stegemann)
  3. Uploader: astegema@ix.urz.uni-heidelberg.de (Achim Stegemann)
  4. Type:     dev/asm
  5.  
  6. This is an updated version compared to last Aminet upload.
  7.  
  8. * The fastsin and fastcos functions speed as been improved.
  9. * Time of table-initialization has been almost halved.
  10. * The cycle timing has been corrected.
  11. * I beg your pardon, but... the polynoms are of degree 2 and not 3 as stated in
  12.   the last version.
  13.  
  14.  
  15. *** History ***
  16.  
  17. When I was programming my first version of Digital Almanac (Aminet:misc/sci),
  18. I saw, that using trigonometric functions take a long time to calculate.
  19. So I thought that there must be a way to be fast but also to be precise.
  20. Using short tables would burst the speed, but wouldnt be precise enough.
  21. Using Taylor series are only fast for values near zero, but would enlengthen
  22. time for values that are closer to 1 or more, but would use no memory.
  23.  
  24. As today everybody has enough RAM in his/hers Amiga, memory consuption is no
  25. more a problem. So I decided to write these functions and make them public.
  26.  
  27.  
  28.  
  29. *** Copyright ***
  30.  
  31. There is no copyright on my idea. Use them as you like it, even if you write
  32. a commercial program. I dont care.
  33. If you have any idea, how to improve speed, tell me !!
  34. Any idea is welcome !!
  35.  
  36.  
  37.  
  38. *** Contents ***
  39.  
  40. This archive contains assembler source codes for PhxAss that shows, how to
  41. program very fast trigonometric functions (sin,cos,asin,acos,atan2) on a
  42. 040/060 CPU.
  43. The source contains interfaces for C, C++ and Assembler stubs.
  44. I myself use PhxAss and StormC V3.
  45.  
  46.  
  47.  
  48. *** Background ***
  49.  
  50. As you know, the 040/060 CPU does not contain those functions. They have to be
  51. emulated by the 680x0.library. This emulation is very time consuming and not
  52. very multi-tasking friendly.
  53. So StormC offers special algorithms to calculate values from those functions
  54. just by using internal FPU commands. To be 100% compatible to FPU, these
  55. functions need to calculate values with an accuracy of 16 digits.
  56. In every-day-purpose a programmer usually does not need that amount of digits.
  57. 10 digits would suffice for their purpose.
  58. This is where my functions join the game.
  59.  
  60. All fast functions offer an accuracy of about 10 to 13 digits (depending on the
  61. initial value.
  62.  
  63.  
  64.  
  65. *** Speed comparison on a 68060/50 ***
  66.  
  67. This table shows a speed comparison of the corresponding FPU commands
  68. on my 68060/50. The times are measured in cycles and might vary by
  69. some cycles.
  70. FF=Fast functions
  71.  
  72.  
  73. Command                  68060.library    StormC    FF (from C)  FF (from Asm)
  74. ------------------------------------------------------------------------------
  75.  
  76. fsin.x fpx                   333           284          83           61
  77. fcos.x fpx                   329           281          82           60
  78. fsincos.x fpx,fpc:fps        416           ---          90          ---
  79. fasin.x fpx                  444           404          98           74
  80. facos.x fpx                  434           391          97           74
  81. atan2(y,x)                   ---           320         211          211
  82.  
  83.  
  84. As you can see, the fast functions are up to 5 times faster than the
  85. original commands.
  86.  
  87. The tan command is not listed here, because tan=sin/cos !!
  88.  
  89.  
  90.  
  91. *** How is it done ? ***
  92.  
  93. Interpolation of sin, cos, asin and acos is realized by using square polynoms.
  94. Starting your program, at first stage tables are filled with polynomial
  95. coefficients.
  96. When you want to receive the value of an input, the program simply evaluates
  97. the corresponding array entry that belongs to your value.
  98.  
  99. E.g. sin(x) = (p[0]*x+p[1])*x+p[2]
  100. where p is the double-pointer to the array of coefficients.
  101.  
  102.  
  103.  
  104. *** Memory consumption ***
  105.  
  106. The sin and cos use a table of 506 kB size.
  107. The asin and acos use a table of each 234 kB size.
  108. The atan2 is transformed into a acos, so its table will be used.
  109. ( atan2(y,x)=acos(x/sqrt(x*x+y+y)) )
  110.  
  111. The initialization of the tables will need about one to two seconds on a 060.
  112.  
  113.  
  114.  
  115. *** Register trashing ***
  116.  
  117. All functions follow the rules for trashing registers (D0/D1,A0/A1,FP0/FP1).
  118. The assembler functions also restore the FP1 register, so only FP0 is filled with
  119. the desired return value.
  120.  
  121. The C/C++ functions also restore the D0 and A0 registers (D1 and A1 are untouched
  122. throughout the code.
  123.  
  124.  
  125.  
  126. *** C includes ***
  127.  
  128. The prototypes of the functions are easy.
  129.  
  130. double fastsin(double);
  131. double fastcos(double);
  132. void   fastsincos(double,double &s,double &c); // (C++)
  133. double fastasin(double);
  134. double fastacos(double);
  135. double fastatan2(double y,double x);
  136.  
  137. I myself have put them into the math.h include.
  138.  
  139.  
  140. ============================= Archive contents =============================
  141.  
  142. Original  Packed Ratio    Date     Time    Name
  143. -------- ------- ----- --------- --------  -------------
  144.     2001     776 61.2% 12-Apr-00 09:39:30 +fastacos.asm
  145.     1984     765 61.4% 12-Apr-00 09:39:30 +fastasin.asm
  146.      946     294 68.9% 12-Apr-00 09:39:30 +fastatan2.asm
  147.     4420    1064 75.9% 11-May-00 01:25:52 +fastsincos.asm
  148.     4612    2051 55.5% 17-Apr-00 17:43:02 +fastsincos.readme
  149.      143     103 27.9% 12-Apr-00 09:41:36 +math.i
  150.    12045    2547 78.8% 12-Apr-00 09:41:58 +PhxMacros.i
  151. -------- ------- ----- --------- --------
  152.    26151    7600 70.9% 12-May-100 01:43:42   7 files
  153.